package cn.tedu._07springaop.egaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LosAspect {
    @Before(value = "execution(public boolean cn.tedu._07springaop.egaop.CartServiceImpl.*(..))")
    public void beforeMethod(){
        System.out.println("开始添加购物车");
    }
    @AfterReturning(value = "execution(public boolean cn.tedu._07springaop.egaop.CartServiceImpl.*(..))",returning = "result")
    public void afterReturningMethod(boolean result){
        if (result){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
    }
    @After(value = "execution(public boolean cn.tedu._07springaop.egaop.CartServiceImpl.*(..))")
    public void afterMethod(){
        System.out.println("操作完成");
    }
//    @Around(value = "execution(public boolean cn.tedu._07springaop.egaop.CartServiceImpl.*(..))")
//    public Object around(ProceedingJoinPoint joinPoint){
//        boolean result = false;
//        try {
//            System.out.println("开始添加购物车");
//            result = (boolean) joinPoint.proceed();
//            if (result){
//                System.out.println("添加购物车成功");
//            }else {
//                System.out.println("添加购物车失败");
//            }
//        }catch(Throwable e){
//            throw new RuntimeException(e);
//        }finally {
//            System.out.println("操作完成");
//        }
//        return result;
//    }
}
